Skip to content

Conversation

aengelberg
Copy link
Contributor

@aengelberg aengelberg commented Aug 13, 2025

Add new ldmiddleware library which provides four HTTP middlewares that can help jumpstart a LaunchDarkly setup:

  • AddScopedClientForRequest - creates a scoped client and adds a ld_request-kind context to it, an anonymous context populated with various attributes of the incoming HTTP request
  • AddScopedClientForRequestWithKeyFn - same except you provide a custom function for determining the key of each request context
  • TrackTiming - track duration metrics using whatever contexts are set so far in the scoped client
  • TrackErrorResponses - track 4xx & 5xx error responses using whatever contexts are set so far in the scoped client

See README.md for sample usage.

Note that these functions are simple enough that consumers could implement their own versions of these if they want the behavior to be slightly different. However, I've set the initial library version as 0.1.0 and am advertising it as an an "alpha" state so we're free to keep making changes.

@aengelberg aengelberg force-pushed the ae/RO-1799/middleware branch from 093094e to b203ea2 Compare August 18, 2025 23:11
@aengelberg aengelberg changed the title Add ldmiddleware package, utilities for creating scoped clients, contexts, events automatically fix(experimental): Add ldmiddleware package, utilities for creating scoped clients, contexts, events automatically Aug 19, 2025
@aengelberg aengelberg changed the title fix(experimental): Add ldmiddleware package, utilities for creating scoped clients, contexts, events automatically fix(experimental): Add ldmiddleware library, utilities for creating scoped clients, contexts, events automatically Aug 19, 2025
@aengelberg aengelberg marked this pull request as ready for review August 19, 2025 00:07
@aengelberg aengelberg requested a review from a team as a code owner August 19, 2025 00:07
@aengelberg aengelberg requested a review from a team August 19, 2025 00:07
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@aengelberg aengelberg merged commit b175f8c into v7 Aug 21, 2025
31 checks passed
@aengelberg aengelberg deleted the ae/RO-1799/middleware branch August 21, 2025 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants